Creating the DataSet for the DataGrid
Now, you will create the DataSet for the DataGrid. You can think of the DataSet as the container for the data that you will display and manipulate in the DataGrid, which you will create later on in the article. Use the following steps to create the DataSet.
- Using the new page you created prior to defining the database connection, save the page as listEmployees.aspx
- In the Application panel, click the Server Behaviors tab.
- The file DreamweaverCtrls.dll (located in C:\Program Files\Macromedia\Dreamweaver MX\Configuration\ServerBehaviors\Shared\ASP.Net\Scripts) must reside in the /bin directory under the root of your website. This file is required by the ASP custom tags provided by Dreamweaver MX. If you haven't already done so, click the deploy link within the Server Behaviors tab. This will copy the DreamweaverCtrls.dll file into the appropriate directory.
-
Next, click the plus button and select DataSet.
Figure 7. Creating the DataSet
- The DataSet dialog appears. Name the DataSet ds_employees.
- Select Northwind from the connection pop-up menu.
- Select dbo.Employees from the Table pop-up menu. (Note that if you are using the Access version of the Northwind database, the table names are not prefaced by “dbo.”)
- Select the Selected: radio button from the Columns: radio button group.
-
The Employees table in the Northwind database contains 18 columns. For this example, select the following 10 columns only (hold the Ctrl key while you select each column):
EmployeeID, LastName, FirstName, HireDate, Address, City, Region, PostalCode, Country, HomePhone
- Since you don't need to filter the query, set Filter to None.
- Since you want to sort alphabetically according to last name, so set Sort to LastName Ascending.
- Click OK to create the DataSet.
-
Save your work.
Figure 8. Specifying the DataSet Attributes
The code that Dreamweaver MX writes for you to create the DataSet for SQL Server is below.
<%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls" Assembly="DreamweaverCtrls,version=1.0.0.0,publicKeyToken=836f606ede05d46a,culture=neutral" %>
<MM:DataSet
id="ds_employees"
runat="Server"
IsStoredProcedure="false"
ConnectionString='<%# System.Configuration.ConfigurationSettings.AppSettings["MM_CONNECTION_STRING_Northwind"] %>'
DatabaseType='<%# System.Configuration.ConfigurationSettings.AppSettings["MM_CONNECTION_DATABASETYPE_Northwind"] %>'
CommandText='<%# "SELECT EmployeeID, LastName, FirstName, HireDate, Address, City, Region, PostalCode, Country, HomePhone FROM dbo.Employees ORDER BY LastName ASC" %>'
Debug="true"
></MM:DataSet>
<MM:PageBind runat="server" PostBackBind="true" />
If you are using Microsoft Access, the code is slightly different. The code that Dreamweaver MX writes for you to create the DataSet for Microsoft Access is shown below. The only difference is the omission of the "dbo." prefix when referencing the Employees database table in the SQL statement/CommandText.
<%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls" Assembly="DreamweaverCtrls,version=1.0.0.0,publicKeyToken=836f606ede05d46a,culture=neutral" %>
<MM:DataSet
id="ds_employees"
runat="Server"
IsStoredProcedure="false"
ConnectionString='<%# System.Configuration.ConfigurationSettings.AppSettings["MM_CONNECTION_STRING_Northwind"] %>'
DatabaseType='<%# System.Configuration.ConfigurationSettings.AppSettings["MM_CONNECTION_DATABASETYPE_Northwind"] %>'
CommandText='<%# "SELECT EmployeeID, LastName, FirstName, HireDate, Address, City, Region, PostalCode, Country, HomePhone FROM Employees ORDER BY LastName ASC" %>'
Debug="true"
></MM:DataSet>
<MM:PageBind runat="server" PostBackBind="true" />
At this point, it's time to explain a couple of other code snippets that Dreamweaver added to your page, specifically the @Register directive and the MM:PageBind tag.
The @ Register directive
Dreamweaver adds the @ Register directive the first time you add any Dreamweaver MX tag to your page. It specifies where to find the code for the Dreamweaver custom tags for the compiler . If you omit this tag, you'll get a parser error from the compiler when you run the page (Parser Error Message: Unknown server tag 'MM:DataSet'.).
< %@ Register TagPrefix="MM" Namespace="DreamweaverCtrls"Assembly="DreamweaverCtrls,version=1.0.0.0,publicKeyToken=836f606ede05d46a,culture=neutral" %>
The MM:PageBind tag
The MM:PageBind tag is a declarative form of the Page.DataBind method. That's a fancy way of saying that if you put a MM:PageBind tag on your page, you generally don't need to worry ever about calling DataBind within your Page_Load method again.
<MM:PageBind runat="server" PostBackBind="true" />
For more information on the Dreamweaver custom tags for ASP.NET, see Russ Helfand and John Albano’s tutorial, Using the Macromedia Dreamweaver MX custom tags for ASP.NET. Now that you’ve created the DataSet, it’s time to display the data on your page by creating the DataGrid.
Submit feedback on our tutorials, articles, and sample applications.